package org.lql.algo.codecrush.hot100.doublePointer;

/**
 * @author: liangqinglong
 * @date: 2025-09-08 11:09
 * @description: 11. 盛最多水的容器 <a href="https://leetcode.cn/problems/container-with-most-water/description/?envType=study-plan-v2&envId=top-100-liked">...</a>
 **/
public class MaxArea {

	public int maxArea(int[] height) {
		if (height.length < 2) {
			return 0;
		}
		int left = 0;
		int right = height.length - 1;
		int ans = 0;
		while (left < right) {
			int minHeight = Math.min(height[left], height[right]);
			int area = (right - left) * minHeight;
			ans = Math.max(ans, area);
			if (height[left] < height[right]) {
				left++;
			} else {
				right--;
			}
		}
		return ans;
	}

	public static void main(String[] args) {
		// 49
		System.out.println(new MaxArea().maxArea(new int[]{1, 8, 6, 2, 5, 4, 8, 3, 7}));
		// 1
		System.out.println(new MaxArea().maxArea(new int[]{1, 1}));
		// 2
		System.out.println(new MaxArea().maxArea(new int[]{1, 2, 1}));
	}
}
